import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/router/keys.dart";
import "package:ct_pa_majordomo/utils/stacker.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";

enum ResultType {
  success,
  fail
}

class ResultPage extends StatefulWidget {
  final ResultType result;
  const ResultPage({super.key, required this.result});

  @override
  State<StatefulWidget> createState() => _ResultPageState();
}

class _ResultPageState extends State<ResultPage> {

  Widget _result() {
    if (widget.result == ResultType.success) {
      return Scaffold(
        appBar: AppBar(
          iconTheme: const IconThemeData(color: Colors.white),
          title: const Text("添加网关", style: TextStyle(color: Colors.white),),
          centerTitle: true,
          backgroundColor: ThemeVars.colorPrimary,
          leading: IconButton(
            icon: const Icon(Icons.arrow_back_ios_new),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
        ),
        body: ListView(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Padding(
                  padding: const EdgeInsets.only(top: 60, bottom: 30),
                  child: Container(
                    decoration: const BoxDecoration(
                      boxShadow: [BoxShadow(color: ThemeVars.colorPrimaryLight, spreadRadius: 5, blurRadius: 5)],
                      color: ThemeVars.colorPrimary,
                      borderRadius: BorderRadius.all(Radius.circular(50)),
                    ),
                    child: const Icon(Icons.check, size: 70, color: Colors.white,),
                  ),
                ),
                const Text("添加成功", style: TextStyle(fontSize: 20),),
                Padding(
                  padding: const EdgeInsets.only(top: 60, right: ThemeVars.paddingPage, bottom: 30, left: ThemeVars.paddingPage),
                  child: SizedBox(
                    width: MediaQuery.of(context).size.width,
                    child: CupertinoButton(
                      color: ThemeVars.colorPrimary,
                      onPressed: () {
                        // Navigator.popUntil(context, ModalRoute. withName("/gateway"));
                        Stacker.pushNamedAndRemoveUntil(Keys.DEVICE_GATEWAY, ModalRoute.withName(Keys.DEVICE_GATEWAY));
                      },
                      child: const Text("完成", style: TextStyle(color: Colors.white),),
                    ),
                  ),
                ),
                const Text("锁与网关需2-3分钟后才能建立连接", style: TextStyle(color: ThemeVars.colorTextTer, fontSize: 12),),
              ],
            ),
          ],
        )
      );
    }
    return Scaffold(
        appBar: AppBar(
          iconTheme: const IconThemeData(color: Colors.white),
          title: const Text("添加网关", style: TextStyle(color: Colors.white),),
          centerTitle: true,
          backgroundColor: ThemeVars.colorPrimaryDark,
          leading: IconButton(
            icon: const Icon(Icons.arrow_back_ios_new),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
        ),
        body: ListView(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Padding(
                  padding: const EdgeInsets.only(top: 60, bottom: 30),
                  child: Container(
                    decoration: const BoxDecoration(
                      boxShadow: [BoxShadow(color: ThemeVars.colorErrorLight, spreadRadius: 5, blurRadius: 3)],
                      color: ThemeVars.colorError,
                      borderRadius: BorderRadius.all(Radius.circular(50)),
                    ),
                    child: const Icon(Icons.close, size: 70, color: Colors.white,),
                  ),
                ),
                const Text("添加失败", style: TextStyle(fontSize: 20),),
                Padding(
                  padding: const EdgeInsets.only(top: 60, right: ThemeVars.paddingPage, bottom: 30, left: ThemeVars.paddingPage),
                  child: SizedBox(
                    width: MediaQuery.of(context).size.width,
                    child: CupertinoButton(
                      color: ThemeVars.colorPrimary,
                      onPressed: () {},
                      child: const Text("重新添加", style: TextStyle(color: Colors.white),),
                    ),
                  ),
                ),
              ],
            ),
          ],
        )
    );
  }

  @override
  Widget build(BuildContext context) {
    return _result();
  }
}